if(!jsx3.lang.Class.forName("ux.cdb.admin.contract.builder.step1.LoanChooser")) {
    jsx3.lang.Class.defineClass("ux.cdb.admin.contract.builder.step1.LoanChooser",
            ux.megatron.gui.WizardPanel,
            null,
            function (block) {
                /**
                 * instance initializer
                 */
                block.prototype.init = function(strName, vntLeft, vntTop, vntWidth, vntHeight, strHTML) {
                    //call constructor for super class (the super expects the name of the object and the function that it is an instance of)
                    this.jsxsuper(strName, vntLeft, vntTop, vntWidth, vntHeight, strHTML);
                };
                
                block.prototype.onAfterDeserialize = function() {
                    this.builder = this.getAncestorOfType("ux.cdb.admin.contract.builder.Builder");
                    this.loaded = false;
					this.currentPage = 1;
                };

                block.prototype.onNext = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
                    if(this.doValidation()) { 
                        var me = this;
                        var nodes = this.matrix.getSelectedNodes();
                        var lockedId = nodes.get(0).getAttribute("appBasicInfoId");
                        ux.megatron.util.Dwr.callDwr("RetailStudentLoanPreContractUCC", "tryLockpreContract", [lockedId], this, function(dwrObject){
                            console.log(this);
                            console.log(dwrObject);
                            if(dwrObject.res.flag == 2){
                                var title = ux.megatron.Main.getServer().getDynamicProperty("@cdb@contract@beLockedTitle");
                                var content = ux.megatron.Main.getServer().getDynamicProperty("@cdb@contract@beLockedContent");
                                var ok = ux.megatron.Main.getServer().getDynamicProperty("@cdb@Btn OK");
                                ux.megatron.Dialog.alert(title, content, function(objDlg){objDlg.doClose();me.loadLoanMatrix()}, ok);
                            } else {
                                this.builder.lockedId = lockedId;
                                this.builder.service.getNewContractInfo(nodes.get(0).getAttribute("appBasicInfoId"), function(o){
                                    //jsx3.log('getNewContractInfo data : ' + dwr.util.toDescriptiveString(o,4));
									/* @JSC :: begin DEBUG */
                                    jsx3.log('getNewContractInfo data : ' + dwr.util.toDescriptiveString(o.content.data[0].partyPersonInfo,4));
                                    /* @JSC :: end */
									this.wizard.newAppBasicInfo = o.content.data[0].appBasicInfo;
                                    try{
                                        this.wizard.newAppBasicInfo.businessParameterValue  = o.content.data[3];
                                        this.wizard.newAppBasicInfo.settleCycleValue 		= o.content.data[4];
                                        var _partyPersonInfo = o.content.data[0].partyPersonInfo;
                                        this.wizard.newAppBasicInfo.partyCertTypeCode  		= _partyPersonInfo.certTypeCode;
                                        this.wizard.newAppBasicInfo.guaranteeCertId  		= _partyPersonInfo.certId;
                                        this.wizard.newAppBasicInfo.guaranteeName  			= _partyPersonInfo.partyName;
                                        this.wizard.newAppBasicInfo.appInternalOrgName 		= o.content.data[5];
                                    }catch(e){/* alert(e.message) */}
                                    this.wizard.certTypeCodeName = o.content.data[1];
                                    this.wizard.curSchoolingInfo = o.content.data[2];
									try{
										var _stuIndividuaInfo = o.content.data[0].stuIndividuaInfo;
										/* @JSC :: begin DEBUG */
	                                    jsx3.log('getNewContractInfo _stuIndividuaInfo : ' + dwr.util.toDescriptiveString(_stuIndividuaInfo,4));
	                                    /* @JSC :: end */
										if(!this.wizard.stuIndividuaInfo)
											this.wizard.stuIndividuaInfo = {};
										this.wizard.stuIndividuaInfo.certId = _stuIndividuaInfo.certId;
										this.wizard.stuIndividuaInfo.partyName = _stuIndividuaInfo.partyName;
									}catch(e){
										jsx3.log('Contrct#wizard#step1#LoanChooser#onNext ERROR:' + e.message);
									}
                                    this.wizard.doNext();
                                }, this);
                            }
                        }, "RetailStudentLoanPreContractUCC");
                        return "NONE";
                    } else {
                        return "NONE";
                    }
                };

                block.prototype.convertNullString = function(obj) {
                    for(var i in obj) {
                        if(obj[i] === "") {
                            obj[i] = null;
                        }
                    }
                    return obj;
                };

                block.prototype.onStepJump =  function(objWIZARD, objSTEP, objEVENT, strCURRENTPANEL){
                    if(this.doValidation()) { 
                        if(this.wizard.newAppBasicInfo) {
                            return null;
                        }
                        var nodes = this.matrix.getSelectedNodes();
                        this.builder.service.getNewContractInfo(nodes.get(0).getAttribute("appBasicInfoId"), function(o){
                            this.wizard.newAppBasicInfo = o.content.data[0].appBasicInfo;
                            this.wizard.certTypeCodeName = o.content.data[1];
                            this.wizard.doNext();
                        }, this);
                        return "NONE";
                    } else {
                        return "NONE";
                    }
                    //return this.doValidation() ? null : 'NONE'; //return "NONE" to cancel the current jumpping..
                };

                block.prototype.onPrev = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
                    return null; // return "NONE" to not advance panels
                };

                block.prototype.onCancel = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
                    this.builder.closeBuilder();
                    return null; // return "NONE" to not advance panels
                };

                block.prototype.onFinish = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL){
                    if(this.doValidation()) { this.builder.saveBuilder(); }
                    return "NONE";
                };

                block.prototype.onBeforeShow = function(objWIZARD, objBUTTON, objEVENT, strLASTPANEL) {
                    try{
                        if(this.builder){
                            this.builder.unLock();
                        }
                    } catch(ex) {
                        console.log(ex);
                    }
                    if(!this.getChild(0)) {
                        ux.megatron.Main.loadUIResourceAsync(this, "ux.cdb.admin",
                            "ux/cdb/admin/contract/builder/step1/ui/loanChooserContent.xml", this, this.initialize);
                    }
                    return null; // return "NONE" to not advance panels
                };

                block.prototype.onAfterHide = function(objWIZARD, objBUTTON, objEVENT, strNEXTPANEL) {
                    return null; // return "NONE" to not advance panels
                };

                block.prototype.initialize = function() {
                    this.loaded = true;
                    this.wizard = this.getAncestorOfType("ux.megatron.gui.SteppedWizard");
                    this.builder = this.getAncestorOfType("ux.cdb.admin.contract.builder.Builder");
                    this.matrix = this.get("mtxMainLoan_S02");
                    this.pagebar = this.get("blkPageWheel");
                    this.pagebar.initialize();
                    this.pagebar.bindWithMatrix(this,this.onPageChange,this.matrix);

                    //this.loadLoanMatrix();

                    this.get("btnRefresh").onClick = jsx3.makeCallback(this.loadLoanMatrix, this);
                    this.get("blkStep1").onClick = jsx3.makeCallback(function() { 
                        this.wizard.getMessageLabel().setText("&nbsp;");
                    }, this);

                    this.get("btnQuery").onClick = jsx3.makeCallback(function() {
                        var params = this.get("blkQuery").getDataAsObject();
                        params = this.convertNullString(params);
                        this.builder.service.queryLoanMatrix(params, this.currentPage, null, function(pageInfo) {
                            this.matrix.repaintData();
                            if(pageInfo) {
                                this.pagebar.setValue(pageInfo.curPage, pageInfo.totalPages, pageInfo.pageSize, pageInfo.totalCount);
                            }
                        }, this);
                    }, this);
                };

                block.prototype.onPageChange = function(msg) {
					this.currentPage = msg.currentPageNumber;
					this.loadLoanMatrix();
                };

                block.prototype.loadLoanMatrix = function() {
                    this.builder.service.loadLoanMatrix(this.currentPage, null, function(pageInfo){
                        this.matrix.repaintData();
                        if(pageInfo) {
                            this.pagebar.setValue(pageInfo.curPage, pageInfo.totalPages, pageInfo.pageSize, pageInfo.totalCount);
                        }
                    }, this);
                };

                block.prototype.displayTip = function(passed) {
                    if(!passed) {
                        var tip = ux.megatron.Main.getServer().getDynamicProperty("@cdb@contractBuilder@TipUnFinishedStep1");
                        this.wizard.getMessageLabel().setText(tip).repaint();
                    } else {
                        this.wizard.getMessageLabel().setText("");
                    }
                    return passed;
                };

                block.prototype.doValidation = function() {
                    var nodes = this.matrix.getSelectedNodes();
                    if(nodes.size() >= 1) {
                        return this.displayTip(true);
                    } else {
                        return this.displayTip(false);
                    }
                };
            }
    );
}
